#include<iostream>
#include<unistd.h>
#include<vector>
using namespace std;
void* threadStrart(void* args)
{
    const char* name =static_cast<const char*>(args);
    while (1)
    {
        std::cout<<name<<" is running "<<std::endl;
        sleep(1);
        break;
    }
    return (void*)3;
    
}
string PrintToHex(int tid)
{
    printf("0x%x",tid);
    char buffer[64];
    snprintf(buffer,sizeof(buffer),"0x%x",tid);
    return buffer;
}

int main()
{
    std::vector<pthread_t>tids;
    for (int i=0;i<10;i++)
    {
         pthread_t tid;
         char *name=new char[128];
         snprintf(name,128,"thread-%d",i);
        pthread_create(&tid,nullptr,threadStrart,/*传递线程名字*/name);
        tids.push_back(tid);
    }
    for(auto tid :tids)
    {
        int arr;
        pthread_join(tid,(void**)&arr); 
        cout<<arr<<endl;
        // printf("%d  quit^^^^^\n",*arr);
    }
   
    // if(n!=0)
    // {
    //     std::cerr <<"creat thread erro"<<std::endl;
    //     return 1;
    // }
    // std::string tid_str=PrintToHex(tid);
    // std::cout<<"tid:"<<tid_str<<endl;
    //主线程
    // std::cout<<"main thread join begin..."<<std::endl;
    // n=pthread_join(tid,nullptr);
    // if(n==0)
    // {
    //     std::cout<<"main thread wait success"<<std::endl;
    // }
    return 0;

}